package com.tan00xu.controller;

import com.tan00xu.service.CommentService;
import com.tan00xu.utils.CmdOutputInformationUtils;
import com.tan00xu.vo.Result;
import com.tan00xu.vo.params.CommentParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 获取文章的评论
     * @param articleId 文章的id
     * @return Result 评论信息
     */
    @GetMapping("/article/{id}")
    public Result getCommentsByArticleId(@PathVariable("id") Long articleId) {
        return commentService.getCommentsByArticleId(articleId);
    }

    /**
     * 发表评论
     * @param commentParam 评论所需参数
     * @return Result
     */
    @PostMapping("/createComment")
    public Result createComment(@RequestBody CommentParam commentParam,@RequestHeader("Authorization") String token) {
        CmdOutputInformationUtils.info("CommentController下的createComment被请求了=>发表评论");
        CmdOutputInformationUtils.error("得到的评论参数：\n"+commentParam);
        return commentService.createComment(commentParam);
    }
}
